<template>
	<view class="modifyPwd">
		<form @submit="formSubmit">
			<view class="current-pwd">
				<text>请输入手机号</text>
				<input class="ipt" placeholder="请绑定您绑定的手机号码" name="bingdingPhone" @input="input" v-model="bingdingPhone" type="number" />
			</view>
			<view class="current-pwd">
				<view class="left" style="display: flex;align-items: center;justify-content: space-between;">
					<text>验证码</text>
					<input class="ipt" placeholder="填写验证码" name="code" @input="input1" v-model="code" type="number" />
				</view>
				<view class="right">
					<text style="color: #FF7200;">获取验证码</text>
				</view>
			</view>
			<view class="current-pwd">
				<text>请输入密码</text>
				<input class="ipt" placeholder="6-16位字符" name="newPwd" @input="input1" v-model="newPwd" type="password" />
			</view>
			<view class="current-pwd">
				<text>确认密码</text>
				<input class="ipt" placeholder="位字符" name="sureNewPwd" @input="input2" @blur="blur" v-model="sureNewPwd" type="password" />
			</view>
			<view class="tips">
				<text>1.密码由8-16位数字、字母或符号组成</text>
				<text style="margin-top: 20rpx;">2.至少包含2种以上字符</text>
			</view>
			<button form-type="submit" class="baocun" :class="isShow?'active':'disable'">确定</button>
		</form>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow: false,
				//验证的规则
				rules: {
					bingdingPhone: {
						rule: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
						// rule:/.{2,18}/,
						msg: "输入格式错误"
					},
					newPwd: {
						rule: /(?!\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,16}/,
						// rule:/.{2,18}/,
						msg: "密码由8-16位数字、字母或符号组成且至少包含2种以上字符"
					},
					sureNewPwd: {
						rule: /(?!\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,16}/,
						// rule:/.{2,18}/,
						msg: "密码由8-16位数字、字母或符号组成且至少包含2种以上字符"
					}
				}
			}
		},
		methods: {
			//表单提交
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value
				console.log(e.detail.value,4444);
				if(formdata.newPwd==formdata.sureNewPwd){
					uni.showModal({
						content: '密码修改成功',
						showCancel: true
					});
				}else{
					uni.showModal({
						content: '两次密码不一致',
						showCancel: false
					});
				}
			},
			blur(){
				if(this.validate('sureNewPwd')&&this.validate('newPwd')&&this.validate('bingdingPhone')){
					this.isShow = true
				}
			},
			input1(e){
				//新密码
				if (!this.validate('newPwd')) {
					return;
				} 
			},
			input2(e){
				//新密码
				if (!this.validate('sureNewPwd')) {
					return;
				} 
			},
			input(e) {
				//原密码验证
				if (!this.validate('bingdingPhone')) {
					return;
				} 
			},
			//判断验证是否符合要求
			validate(key) {
				let bool = true;
				if (!this.rules[key].rule.test(this[key])) {
					//提示信息
					uni.showToast({
						title: this.rules[key].msg,
						icon: 'error'
					})
					//取反
					bool = false;
					return false;
				}
				return bool;
			},
		}
	}
</script>

<style scoped lang="less">
	.ipt{
		margin-left: 20rpx;
	}
	.modifyPwd {
		padding: 40rpx;

		.tips {
			margin-top: 40rpx;
			display: flex;
			flex-direction: column;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #999999;
		}

		.current-pwd {
			margin-bottom: 20rpx;
			width: 100%;
			height: auto;
			background: #FFFFFF;
			opacity: 1;
			display: flex;
			align-items: center;
			padding: 5rpx 24rpx;

			text {
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}

		}

		.baocun {
			margin-top: 80rpx;
			width: 100%;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			opacity: 1;
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
		}

		.disable {
			background-color: #D8D8D8;
		}

		.active {
			background-color: #FF7200;
		}
	}
</style>

 
 
 
 